package com.ray.controller.user;

import com.ray.pojo.User;
import com.ray.service.UserService;
import com.ray.service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class GetAllUserController extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {

        // 实例化UserService
        UserService userService = new UserServiceImpl();

        // 调用相应方法获得用户pojo
        List<User> allUser = userService.getAllUser();

        // 设置request属性
        req.setAttribute("alluser", allUser);

        // 转发request和response
        req.getRequestDispatcher("/index.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        doGet(req, resp);
    }
}
